package com.xframe.xdal.core.serialize.lang.staticlist;



import com.xframe.xdal.core.util.StringUtil;

import java.util.HashMap;
import java.util.Map;


public class StaticListLanguageItem {

    private Map<String, StaticListItem> modelAttrMap = new HashMap<>();


    public void add(String mapKey, StaticListItem staticListItem){

        modelAttrMap.put(mapKey,staticListItem);
    }


    public Object getListItem(String attrName,Object value){
        StaticListItem staticListItem = modelAttrMap.get(attrName);
        if(staticListItem == null){
            return value;
        }
        if(staticListItem.getValList() == null){
            return staticListItem.getDefVal();
        }
        String strVal = value == null ? StringUtil.EMPTY : value.toString();
        for(ListItem listItem : staticListItem.getValList()){
            if(listItem.valEqual(strVal)){
                return listItem.getLabel();
            }
        }
        return staticListItem.getDefVal();
    }
}
